Skip to content

feat: add packet_loss toxic for simulating flaky network conditions#739

Open
maskedmaxx wants to merge 2 commits into
Shopify:mainfrom
maskedmaxx:feature/packet-loss-toxic
Open

feat: add packet_loss toxic for simulating flaky network conditions#739
maskedmaxx wants to merge 2 commits into
Shopify:mainfrom
maskedmaxx:feature/packet-loss-toxic

Conversation

@maskedmaxx

@maskedmaxx maskedmaxx commented Jun 6, 2026

Copy link
Copy Markdown

Overview

Adds the packet_loss toxic to toxiproxy, filling a gap for simulating flaky network conditions like poor Wi-Fi, mobile networks, and satellite links.

What's included

  • packet_loss.go: Core implementation using a simplified Gilbert-Elliott burst model
  • packet_loss_test.go: Comprehensive test suite covering edge cases
  • README.md: Documentation with attributes and examples

Features

  • loss_rate: Probability [0.0–1.0] that a chunk is dropped (default: 0.1)
  • correlation: Extra drop probability when previous chunk was dropped, modeling burst loss (default: 0.0)
  • Per-connection RNG to avoid contention between concurrent connections
  • Automatic registration via init()

Testing

All tests pass locally:

$ go test -v ./toxics/ -run TestPacketLoss
=== RUN   TestPacketLossToxicNoLoss
--- PASS: TestPacketLossToxicNoLoss (0.00s)
=== RUN   TestPacketLossToxicFullLoss
--- PASS: TestPacketLossToxicFullLoss (0.00s)
=== RUN   TestPacketLossToxicApproximateRate
--- PASS: TestPacketLossToxicApproximateRate (0.00s)
=== RUN   TestPacketLossToxicIndependentConnections
--- PASS: TestPacketLossToxicIndependentConnections (0.00s)
=== RUN   TestPacketLossToxicPipeDrains
--- PASS: TestPacketLossToxicPipeDrains (0.00s)
PASS
ok      github.com/Shopify/toxiproxy/v2/toxics  1.065s

Usage examples

$ toxiproxy-cli create -l localhost:26379 -u localhost:6379 myproxy
$ toxiproxy-cli toxic add -t packet_loss -a loss_rate=0.1 -a correlation=0.3 myproxy

@maskedmaxx

Copy link
Copy Markdown
Author

I have signed the CLA!

…- Implements Gilbert-Elliott burst model for realistic packet loss patterns

- Per-connection RNG to avoid contention between concurrent connections
- Comprehensive test coverage with all tests passing
- Documented in READMe with usage examples
@maskedmaxx maskedmaxx force-pushed the feature/packet-loss-toxic branch from 80806fc to 7e3cd36 Compare June 6, 2026 18:18
@maskedmaxx

Copy link
Copy Markdown
Author

CLA check failing due to IP allow list restriction on my side. Let me know if you need anything from me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant